package file_demo1;

import java.io.*;

public class demo_text1 {
    public static void main(String[] args) throws IOException {
        //原文件
        File f = new File("");
        //拷贝后的文件
        File desk = new File("");
        dg(f, desk);

    }

    public static void dg(File f,File desk) throws IOException {
        //创建文件  失败也不会报错
        desk.mkdirs();
        File[] files = f.listFiles();
        for(File file : files){
            if(file.isFile()){
                FileInputStream fis = new FileInputStream(file);
                //注意路径， 要烤进文件里面
                FileOutputStream fos = new FileOutputStream(new File (desk, file.getName()));

                byte[] b = new byte[1024];
                int len;
                while((len = fis.read()) != -1){
                    fos.write(b,0,len);
                }

                fos.close();
                fis.close();

            }   else{
                dg(file,new File(desk, file.getName()));
            }
        }
    }
}
